package com.jiji.miaosha.mapper;

import com.jiji.miaosha.entity.ItemStock;
import org.apache.ibatis.annotations.*;

@Mapper
public interface ItemStockMapper {

    @Select("select * from item_stock where item_id=#{itemId}")
    ItemStock queryStockByItemId(@Param("itemId") Integer itemId);

    @Insert("insert into item_stock(id,stock,item_id) values(#{stock.id},#{stock.stock},#{stock.itemId})")
    @Options(useGeneratedKeys = true, keyProperty = "stock.id")
    int insertSelective(@Param("stock") ItemStock itemStock);

    @Update("update item_stock set stock=stock-#{amount} where item_id=#{itemId} and stock>=#{amount}")
    int decreaseStock(@Param("itemId") Integer itemId,@Param("amount") Integer amount);
}
